package com.gaojun.mybatisspring;

import com.gaojun.mapper.OrderMapper;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;
import java.util.Map;

/**
 * @author ：gaojun
 * @date ：Created in 2022/9/26 22:20
 * @description：注册器
 * @modified By：
 * @version: 1.0$
 */
public class GaoJunBeanDefinitionResgistrer implements ImportBeanDefinitionRegistrar {
	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry, BeanNameGenerator importBeanNameGenerator) {
		Map<String, Object> annotationAttributes=importingClassMetadata.getAnnotationAttributes(GaoJunMapperScan.class.getName());
		String path=(String) annotationAttributes.get("value");
		GaojunBeanDefinitionScan scanner=new GaojunBeanDefinitionScan(registry);
		scanner.addIncludeFilter(new TypeFilter() {
			@Override
			public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
				return true;
			}
		});
		scanner.scan(path);

	}
}
